package com.niit.order;


import com.niit.feign.clients.UserClient;
import com.niit.feign.fallback.UserClientFallback;
import com.niit.order.fallback.MyUserClientFallback;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @author yaojianfeng
 */
@MapperScan("com.niit.order.mapper")
@ServletComponentScan(basePackages = {"com.niit.order.filter"})
@SpringBootApplication
@EnableHystrix
@EnableFeignClients(clients = {UserClient.class})
public class OrderApplication {

    public static void main(String[] args) {
        SpringApplication.run(OrderApplication.class, args);
    }

    /**
     * 注册RestTemplate 并添加负载均衡能力注解
     * @return RestTemplate
     */
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }


    /**
     * 声明服务降级类,解决UserClientFallback实例无法找到异常
     * @return
     */
    /*@Bean
    public UserClientFallback userClientFallback(){
        return new UserClientFallback();
    }*/


    /**
     * 注入order-service自定义的 MyUserClientFallback服务降级类
     * @return
     */
    @Bean
    public UserClientFallback userClientFallback(){
        return new MyUserClientFallback();
    }
}